import threading

num = 0

mutex = threading.Lock()


def add(count):
    mutex.acquire()
    global num
    for i in range(count):
        num += 1
    print("num=",num)
    mutex.release()


if __name__ == '__main__':
    t1 = threading.Thread(target=add, args=(1000000,))
    t2 = threading.Thread(target=add, args=(1000000,))
    t1.start()
    t2.start()
